unit colorbutton;

{$mode objfpc}{$H+}

interface

uses
  Classes, {$IFDEF MSWINDOWS} windows, {$ENDIF} SysUtils, ExtCtrls, Controls;

type

  { TColorButton }

  { TAnyColorButton }

  TAnyColorButton = class(TCustomPanel)
  protected
    procedure Paint; override;
    procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
      override;
    procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  public
    constructor Create(TheOwner: TComponent); override;
  published
    property Align;
    property Alignment;
    property Anchors;
    property AutoSize;
    property BorderSpacing;
    property BevelInner;
    property BevelOuter;
    property BevelWidth;
    property BidiMode;
    property BorderWidth;
    property BorderStyle;
    property Caption;
    property ChildSizing;
    property ClientHeight;
    property ClientWidth;
    property Color;
    property Constraints;
    property DockSite;
    property DragCursor;
    property DragKind;
    property DragMode;
    property Enabled;
    property Font;
    property FullRepaint;
    property ParentBidiMode;
    property ParentColor;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property ShowHint;
    property TabOrder;
    property TabStop;
    property UseDockManager default True;
    property Visible;
    property OnClick;
    property OnContextPopup;
    property OnDockDrop;
    property OnDockOver;
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDock;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnGetSiteInfo;
    property OnGetDockCaption;
    property OnMouseDown;
    property OnMouseEnter;
    property OnMouseLeave;
    property OnMouseMove;
    property OnMouseUp;
    property OnResize;
    property OnStartDock;
    property OnStartDrag;
    property OnUnDock;
  end;

  { TProductButton }

  TProductButton = class(TAnyColorButton)
  private
    fProductID: Integer;
    fPrice: single;
    fDepartment: integer;
  published
    property ProductID: Integer read FProductID write FProductID;
    property Price: single read fPrice write fPrice;
    property Department: Integer read fDepartment write fDepartment;
  end;

implementation

uses Graphics;

{ TColorButton }

procedure TAnyColorButton.Paint;
var
  r: TRect;
  st: TTextStyle;
begin
  inherited Paint;
  r := ClientRect;
  Brush.Color := Color;
  Brush.Style := bsSolid;
  if BevelOuter=bvLowered then
     begin
       r.Top := 2;
       r.Left := 2;
     end;
  Canvas.FillRect(r);
  st.Alignment := taCenter;
  st.Wordbreak := true;
  st.SingleLine := false;
  st.Layout := tlCenter;
  Self.Canvas.TextRect(r, 0, 0, Caption, st);
end;

procedure TAnyColorButton.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
  Y: Integer);
begin
  inherited MouseDown(Button, Shift, X, Y);
  BevelOuter := bvLowered;
  Paint;
end;

procedure TAnyColorButton.MouseUp(Button: TMouseButton; Shift: TShiftState; X,
  Y: Integer);
begin
  inherited MouseUp(Button, Shift, X, Y);
  BevelOuter := bvRaised;
end;

constructor TAnyColorButton.Create(TheOwner: TComponent);
begin
  inherited Create(TheOwner);
  BevelWidth := 2;
end;

{ TProductButton }

end.

